package Com.Hupochuan.Uil.Do;

import java.util.Hashtable;

import Com.Hupochuan.Dal.Tab.FeedBackTab;
import Com.Hupochuan.Uil.Servlet.DoRunServlet;
import Com.Tester.Tester;

@SuppressWarnings("serial")
public class AjaxDo extends DoRunServlet{
	public void doRun(){
		
		//打印测试
		Tester.print("打印测试 - AjaxDo");
		
		//获得参数
		String action = this.getDoTool().getPara("action");

		//打印测试
		Tester.print("打印测试 - action：" + action);
		
		//返回Hashtable
		Hashtable<String,String> returnHash = new Hashtable<String,String>();
		
		//意见反馈
		if(action.equals("feedBack")){
			this.feedBack(returnHash);
		}
		
		//发送回客户端页面
		this.getDoTool().sendMsg(returnHash);
	}
	
	/*
	 * 意见反馈
	 */
	private void feedBack(Hashtable<String,String> returnHash){
		String content = this.getDoTool().getPara("content");
		String linkman = this.getDoTool().getPara("linkman");
		String validateCode = this.getDoTool().getPara("validateCode");
		String url = this.getDoTool().getPara("url");
		String ip = this.getDoTool().getIp();
		String SessionValidateCode = (String)this.getDoTool().getSess("SessionValidateCode");
		
		//内容为空
		if(content.equals("")){
			returnHash.put("stateCode","content_isnull");
			return;
		}
		
		//内容超长
		if(content.length() >= 2000){
			returnHash.put("stateCode","content_overlength");
			return;
		}
		
		//联系方式超长
		if(linkman.length() >= 200){
			returnHash.put("stateCode","linkman_overlength");
			return;
		}
		
		//验证码为空
		if(validateCode.equals("")){
			returnHash.put("stateCode","validateCode_isnull");
			return;
		}
		
		//到这里就可以清除验证码的Session了（用于防止同Session高并发攻击）
		this.getDoTool().removeSess("SessionValidateCode");
		
		//验证码错误
		if(SessionValidateCode == null || !validateCode.toUpperCase().equals(SessionValidateCode.toUpperCase())){
			returnHash.put("stateCode","validateCode_error");
			return;
		}
		
		Tester.print("content:"+content);
		Tester.print("linkman:"+linkman);
		Tester.print("validateCode:"+validateCode);
		Tester.print("url:"+url);
		Tester.print("ip:"+ip);
		
		//执行添加反馈数据
		FeedBackTab.getObject().appendData(content, linkman, url, ip);
		
		returnHash.put("stateCode","success");
	}
}
